package practice;

import java.util.LinkedList;
import java.util.Stack;

class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;

//构造方法
    public MyQueue() {
    stack1 = new Stack<>();
    stack2 = new Stack<>();
    }
    //入队:入不为空的栈
    public void push(int x) {
        stack2.push(x);

    }

    //出队:先倒序 将不为空的栈里的元素全部压入为空的栈里
    public int pop() {
        if(empty()){
            return  -1;
        }if(stack1.empty()){//将stack里的元素都到过来
            while (!stack2.empty()){
                stack1.push(stack2.pop());
            }
        }

        return stack1.pop();//stack不为空,就继续出队
    }

    public int peek() {
        if(empty()){
            return  -1;
        }if(stack1.empty()){
            while (!stack2.empty()){
                stack1.push(stack2.pop());
            }
        }
        return stack1.peek();
    }
    
    public boolean empty() {
        return stack1.empty() && stack2.empty();
    }
}